package com.fjnldx.mes.service.scheduling.alarm.rule.relieve;

import com.alibaba.fastjson.JSONObject;
import com.fjnldx.mes.domain.pojo.alarm.AlarmRecord;
import com.fjnldx.mes.domain.pojo.alarm.AlarmRules;
import com.fjnldx.mes.domain.pojo.alarm.enums.RelieveTypeEnum;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.time.LocalDateTime;

/**
 * 自动解除检查
 */
@Service
public class AutoCheck implements AlarmRelieveCheck {
    @Override
    public RelieveTypeEnum RelieveType() {
        return RelieveTypeEnum.AUTO;
    }

    @Override
    public Boolean Check(AlarmRules rule, AlarmRecord record) {
        JSONObject relieve = JSONObject.parseObject(rule.getRelieveValue());
        relieve.getInteger("time");
        Duration duration = Duration.between(record.getCreateTime(), LocalDateTime.now());
        return relieve.getInteger("time") <= duration.toMinutes();
    }
}
